package com.bw.unit3.widgit

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.widget.TextView
import com.bw.unit3.R

class LoadingDialog : Dialog {

    private lateinit var tipView: TextView

    fun toShow() {
        if (!this!!.isShowing) {
            dismiss()
            show()
        }
    }

    fun toDismiss() {
        dismiss()
    }

    constructor(context: Context, defaultTip: String? = null) : super(context) {
        setCanceledOnTouchOutside(false)//按对话框以外的地方不起作用，按返回键可以取消对话框
        //setCancelable(false)
        window?.setGravity(Gravity.CENTER)
        setContentView(R.layout.layout_loading)
        tipView = findViewById(R.id.tv_wait_dialog_text)
        if (!defaultTip.isNullOrEmpty()) tipView.text = defaultTip
    }

    fun setContent(content: String) {
        tipView.text = content
    }

    override fun hide() {
        super.hide()
        dismiss()
    }


}